<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Contacts extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		
		$this->load->helper('form');
	}

	function index()
	{
		$this->load->helper('url');
		$this->load->helper('form');
		$this->load->library('Menu');
		$this->load->helper('security');
		$this->load->library('email');
		
		// intial email
		$mailconf['mailtype'] = 'html';
		$this->email = new CI_Email($mailconf);
		
		$menu = new Menu;
		$user =& Users::getInstance();
		
		$data = $menu->gen();
		$data['user'] = $user;
		
		if ($user->id > 0) {
			if ($user->level > 0) {
				$data['stats']['oncoming'] = $this->Jobs->getOncoming(-1, true);
				$data['stats']['quote'] = $this->Jobs->getNeedQuote(-1, true);
			}
			$this->load->view('contacts', $data);
		} else {
			$this->load->view('contacts-guest', $data);
		}
	}
	
	function send()
	{
		$this->load->helper('url');
		$this->load->helper('form');
		$this->load->library('Menu');
		$this->load->helper('security');
		$this->load->library('email');
		
		// intial email
		$mailconf['mailtype'] = 'html';
		$this->email = new CI_Email($mailconf);
		
		$menu = new Menu;
		$user =& Users::getInstance();
		
		$data = $menu->gen();
		$data['user'] = $user;
		
		$this->email->from($this->input->post('mail'), $this->input->post('name'));
		$this->email->to('ivy@bookabus.sg');
		
		$this->email->subject($this->input->post('subject'));
		$this->email->message($this->input->post('msg'));
		
		$message = '<p>Your contact form have been sent.</p>';
		
		$data['lpmessage'] = $message;
		
		$this->load->view('contacts-msg', $data);
	}
}

/* End of file user.php */
/* Location: ./application/controllers/user.php */